Stored Procedures, MySQL and PHP

前端 未结 5 1568
故里飘歌
故里飘歌 2020-11-30 08:35

The question is a fairly open one. I\'ve been using Stored Procs with MS SQLServer for some time with classic ASP and ASP.net and love them, lots.

I have a small hob

5条回答
  •  萌比男神i
    2020-11-30 09:02

    You'll need to use MySQLI (MySQL Improved Extension) to call stored procedures. Here's how you would call an SP:

    $mysqli = new MySQLI(user,pass,db);
    
    $result = $mysqli->query("CALL sp_mysp()");
    

    When using SPs you'll need close first resultset or you'll receive an error. Here's some more information :

    http://blog.rvdavid.net/using-stored-procedures-mysqli-in-php-5/ (broken link)

    Alternatively, you can use Prepared Statements, which I find very straight-forward:

      $stmt = $mysqli->prepare("SELECT Phone FROM MyTable WHERE Name=?");
    
      $stmt->bind_param("s", $myName);
    
      $stmt->execute();
    

    MySQLI Documentation: http://no.php.net/manual/en/book.mysqli.php

提交回复
热议问题