1

I would like to know how to use the common mysql_* stuff. I don't take to make SO a mess and make a question for each one, so I just put up this question with a small list:

  • num_rows
  • fetch_array
  • set_charset
  • fetch_row

This is the functions you use to normal mysql_* queries, what are the PDO´s functions equals to these?

And how can you INSERT INTO, UPDATE and DELETE

The only thing I know and tested right now is connect to the db + selecting like this:

$conn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);
$sql  = "SELECT id FROM users";
$q    = $conn->query($sql) or die("failed!");

What I expect for an answer is either links to each function and attributes
(num_rows, fetch_array, insert into, update, etc..) or direct answers to them.

2 Answers 2

2

$q = $conn->query($sql) or die("failed!");

Don't do that. Use:

$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

Then you'll get an exception if something goes wrong with the query.

Sign up to request clarification or add additional context in comments.

Comments

1

have a look at the documentation: http://php.net/manual/en/book.pdo.php Its all in there

2 Comments

Yes but I am getting confused such as this. Should i use e.g $r = $sql->fetch(PDO::FETCH_ASSOC) or $r = $sql->fetch() they both work same way?
Also mentioned there: fetch() use FETCH_BOTH by default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.