Deprecated: mysql_query() [duplicate]

i just update my server. it showing an error today Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the >future: use mysqli or PDO instead in C:\wamp\www\work\db\dbfields – Copy.php on line 33 my dbfields – Copy.php page is mysql_query(“insert into user(name,address) values(‘$name’,’$address’)”); i create 2 columns (name&address), need to insert the … Read more

What is the advantage of using try {} catch {} versus if {} else {}

I’d use the try/catch block when the normal path through the code should proceed without error unless there are truly some exceptional conditions — like the server being down, your credentials being expired or incorrect. I wouldn’t necessarily use it to handle non-exceptional errors — say like the current user not being in the correct … Read more

PDO closing connection

Just a rather simple question with regards to PDO compared to MySQLi. With MySQLi, to close the connection you could do: However with PDO it states you open the connection using: but to close the connection you set it to null. Is this correct and will this actually free the PDO connection? (I know it … Read more

Are PDO prepared statements sufficient to prevent SQL injection?

The short answer is NO, PDO prepares will not defend you from all possible SQL-Injection attacks. For certain obscure edge-cases. I’m adapting this answer to talk about PDO… The long answer isn’t so easy. It’s based off an attack demonstrated here. The Attack So, let’s start off by showing the attack… In certain circumstances, that will return more than … Read more

pdo – Call to a member function prepare() on a non-object

$pdo is undefined. You’re not declaring it inside the function, and it isn’t being passed in as an argument. You need to either pass it in (good), or define it in the global namespace and make it available to your function by placing global $pdo at the top (bad).

PDO bindParam() with prepared statement isn’t working

Using bindParam() the variable is bound as a reference. A string can’t be passed by reference. The following things can be passed by reference: Variables, i.e. foo($a) New statements, i.e. foo(new foobar()) References returned from functions Try using bindValue()