无法使用MySqli连接到数据库

时间:2016-11-20 09:59:30

标签: php mysql mysqli

我的朋友为我写了一段代码,已经有一段时间了。我已经修改了一些代码以重用mysqli,因为很快就会删除mysql。看起来像这样 logininfo.php

    <?php
class logininfo
{

    private  $settings;

    function getSettings() {

        // Database variables
        $settings['dbhost'] = 'localhost';
        $settings['dbusername'] = 'root';
        $settings['dbpassword'] = '123456789';
        $settings['dbname'] = 'robm';

        return $settings;

    }

}
?>

datbaseconnect.php

 <?php
require_once 'libraries/database.logininfo.php';

class dbconnect extends logininfo {


    function getSettings(){

        // Load settings from parent class
        $settings = logininfo::getSettings();
        //function loadSettings() {
        // Get the main settings from the array we just loaded
        $host = $settings['dbhost'];
        $db = $settings['dbname'];
        $user = $settings['dbusername'];
        $pass = $settings['dbpassword'];

        $connect= mysql_connect($host, $user, $pass,$db) or die ("Sorry, Could not Connect Database! Error Code #3");
        //$dbconct= mysql_select_db($db) or die("Sorry, Unable to Connect Databse! Error Code #2");

        return ($connect);

    }
}
?>

无论我在哪里使用

require_once 'libraries/database.connect.php';
                                $con1= @dbconnect::getSettings();

我能够访问mysql。

我的查询

$result1=sprintf("SELECT name,age,gender,email,timezone, timestamp FROM $name WHERE symbol='%s'AND series='%s' AND timestamp BETWEEN '%s' AND '%s' ORDER BY timestamp",mysqli_real_escape_string($firstname),mysqli_real_escape_string($series),mysqli_real_escape_string($lastname),
                mysqli_real_escape_string($thirdname));         $result=mysqli_query($result1)or die(mysql_error());        while ($row = mysql_fetch_assoc($result)){          $dateOytPut=$row['timestamp'];          $nameOutPut=$row['name'];           $ageOutPut=$row['age'];             $genderOutPut=$row['gender'];           $emailOutPut=$row['email'];             $tradQtyOutPut=$row['timezone'];

未修改的代码仍可与mysql_ string一起使用。问题现在,如果我将其更改为mysqli然后,以前它抛出500内部错误。现在我收到警告:mysqli_real_escape_string()正好需要2个参数,给定1个。我在这里做错了什么?

0 个答案:

没有答案