Php命令行脚本无法使用MYSQLI连接到服务器

时间:2015-04-24 12:05:54

标签: php mysql mysqli

我正在尝试使用此命令行脚本。它将图像添加到已存在的数据库和表中。服务器上安装了Wamp服务器,我可以从另一台计算机访问它。但每次我运行脚本时,脚本都会在连接时挂起。

<?php
   error_reporting(E_ALL);
   ini_set('display_errors', 1);
   $filename = $argv[1];
   //$filename="images/image10.jpg";
   $imgData = file_get_contents($filename);
   $size = getimagesize($filename);

   $servername="192.168.0.34";
   $username="root";
   $password="password";
   $dbname = "test";
   $conn = new mysqli($servername, $username, $password, $dbname);

   // check connection
   if($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
   }

   echo "Connection successful";

   // insert into table
   $sql = sprintf("insert into images(image_type, image, image_size, image_name) values('%s', '%s', '%d', '%s')",
   mysql_real_escape_string($size['mime']),
   mysql_real_escape_string($imgData),
   $size[3],
   mysql_real_escape_string($_FILES['userfile']['name']));

   if($conn->query($sql) === TRUE) {
      echo "Inserted new image successfully";
   } else {
      echo "Error inserting image: " . $conn->error;
   }

   echo "Closing the connection";
   $conn = null;

   ?>

我只在客户端上安装了php和php-mysql。客户端正在运行debian,服务器正在运行Windows 7.我错过了我需要安装的其他内容吗?

谢谢

1 个答案:

答案 0 :(得分:0)

您需要在系统上安装mysqli。请参阅:http://php.net/manual/en/mysqli.installation.php