SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)

    Mulitiple line sql statements using PDO?

    Hi,

    I am setting up some test data prior to unit testing some classes wot I am writing.

    Anyone know the best way to use PDO to input multiple lines of sql, I feel silly, but am stumped by this issue.

    Writing loads of lines like this in my setup, seems mad...

    PHP Code:
    $stmt $PDO->prepare("INSERT INTO `results` VALUES (5, 5, 3, 1, 916);");
    $stmt->execute(); 
    How do you add a multiline sql statement using PDO?

    Thanks for any help.

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2003
    Location
    Melbourne, Australia
    Posts
    440
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As far as I can tell, it's not possible. PDO has no equivalent to mysqli_multi_query().

    If you can get all your test values into an array, you could use a prepared statement with placeholders and use PDOStatement::bindParam() and PDOStatement::execute() in a loop. Something like
    PHP Code:
    $stmt $PDO->prepare("INSERT INTO `results` VALUES (?, ?, ?, ?, ?);");
    foreach(
    $values_array as $values) {
        foreach(
    $values as $key => $value) {
            
    $stmt->bindParam($key 1$valuePDO::PARAM_INT);
        }
        
    $stmt->execute();

    Zealotry is contingent upon 100 posts and addiction 200?

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by auricle View Post
    As far as I can tell, it's not possible. PDO has no equivalent to mysqli_multi_query().
    Cheers Auricle, I was about to post inserting with prepare from a tutorial I found.

    Thanks all the same.

    Paul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •