Welcome Guest, Not a member yet? Register   Sign In
$this versus mysql
#1

[eluser]tim1965[/eluser]
Hi

Can somebody explain what the difference is between these two queries. The first $this wouldnt work on my system, but the mysql would. So i owuld be grateful for an explanation of the difference between these two statements

Thansk



$latest_id = $this->db->insert_id();

$latest_id = mysql_insert_id();
#2

[eluser]Colin Williams[/eluser]
One will work if you change database drivers (say you switch to PostgreSQL) and one will only work with MySQL.

Also, what does "wouldn't work" mean exactly. Did you get an error?
#3

[eluser]Pascal Kriete[/eluser]
The first one uses the CodeIgniter database class which supports a variety of database types (postgre, mysql(i), odbc, etc).

If you're connecting to a mysql database, CI will use mysql_insert_id internally so in that case the two statements are essentially the same. The former will make your application more portable as it provides a unified syntax for the different database types.

As to why it doesn't work:
1) Did you load the database class?
2) What query are you running?
3) Where are you using this (controller, model, library)? Do you get any errors?


Grrr, seconds slower than Colin. Tongue
#4

[eluser]tim1965[/eluser]
i fixed the problem and managed to get the $this working. The problem was that i wasnt calling it using the correct path.
I was just interested as to what the difference was between them. Many thanks for your time and explanations.




Theme © iAndrew 2016 - Forum software by © MyBB