mysqli(我认为)和php

时间:2017-07-24 03:37:27

标签: php mysql mysqli

我几天前发布在这里,并被标记为重复。我纠正了(据我所知)我的代码中的所有mysql / mysqli不一致。据我所知,这应该有效。但是,我得到的只是第一个标题,以及CSS的一些基础知识(背景颜色和边框/容器)。它没有在浏览器中给出错误,并且/ var / log /中没有任何错误。我甚至完全建立了一个全新的Web服务器。有一天,当我在Ubuntu 15.04上发布时,我决定转移到CentOS 7.我还升级到了php v7。我在这个虚拟机上托管了2个其他网站,它们都运行良好 - 它们只是wordpress网站。我真的经历了每一页的每一行代码,我无法在这里找出问题所在。

请不要禁止我 - 如果这是一个重复的某种方式(即使花了几个小时寻找问题所在的一些迹象 - 我认为这是问题所在,我无法确定它在哪里&# #39; s不能正常工作)请让我知道它是如何复制的。我做的最后一篇文章发生了变化,但因为它被标记为重复,没有人能看到更新,也没有任何问题得到解决。我是一个全职的系统管理员,并且非常想成为网络开发人员,只是寻找那些比我更聪明的人的帮助。

反正。我在所有页面上都遇到了同样的问题。要么我得到基础知识,如标题和背景,没有实际数据,或者我只是得到背景。

phpfunctions.php (这在所有网页上都有引用)

这只是其中的一个示例,但它们都遵循相同的格式,这在我开始添加页面并更改为mysqli之前有效(我只添加了2个函数,两者都是在所有这些变化之前,它们正在工作)

<?php

    function db_connect() {

        static $connection;

        if(!isset($connection)) {

            $config = parse_ini_file('/info/config.ini'); 
            $connection = mysqli_connect($config['dbname'],$config['username'],$config['password'],$config['dbname'],'3306');

            }

        if($connection === false) {

            return mysqli_connect_error(); 

            }

        return $connection;
    }

    function close(){
        mysqli_close();
    }

    function make(){
        $qmake = mysqli_query( "SELECT VMakeID, VMake FROM vmake ORDER BY vmake");
        while($record = mysqli_fetch_array($qmake)){
            echo '<option value="' . $record['VMakeID'] . '">' . $record['VMake'] . '</option>';
        }
    }

?>

的index.php 我想如果我能弄清楚为什么这个页面不起作用,那么剩下的就会到位,因为这似乎是一个普遍的问题。

<head>

<title>Jeremy Cherokee</title>

<link rel="icon" type="image/png" href="images/favicon.ico" type="image/x-icon"/>
<link href="css/justanerd.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/sidebar.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/header.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/tables.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/banner.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/footer.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/buttons.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="css/forms.css" rel="stylesheet" type="text/css" media="screen"/>
<link href="files/print.css" rel="stylesheet" type="text/css" media="print"/>

<?php

    include_once 'php/phpfunctions.php';
    db_connect();

?>

</head>

<body>

    <div class="container">

        <?php include ("layout/header.php"); ?>

        <?php include ("layout/banner.php"); ?>

        <div class="maininfo">
            <h2>
                My Garage
            </h2>
            <div class="current">

                <?php

                    $sql = "    SELECT  vehicles.VYear, 
                                        vmake.VMake, 
                                        vmodel.VModel, 
                                        vehicles.VTrim, 
                                        vehicles.VehicleID,
                                        vehicles.VThumbnail

                                FROM    vehicles 
                                        INNER JOIN mycars.vmake ON vehicles.VMakeID = vmake.VMakeID
                                        INNER JOIN mycars.vmodel ON vehicles.VModelID = vmodel.VModelID

                                WHERE vehicles.VCurrentlyOwn = '1'";

                    $result = mysqli_query($sql)or die(mysqli_error());

                    echo "<table>";
                    echo "  <tr>
                                <th>Year</th>
                                <th>Make</th>
                                <th>Model</th>
                                <th>Trim</th>
                                <th>".'<a href="newcar.php"><img src="images/addnew.png" width="33px" height="25px"></a>'."</th>
                                <th>".'<img src="images/redx.png" width="33px" height="25px">'."</th>
                            </tr>";

                    while($row = mysqli_fetch_array($result)){

                        $year   =   $row['VYear'];
                        $make   =   $row['VMake'];
                        $model  =   $row['VModel'];
                        $trim   =   $row['VTrim'];
                        $vid    =   $row['VehicleID'];
                        $pic    =   $row['VThumbnail'];

                        echo "  <tr>
                                    <td style='width: 50px;'>".$year."</td>
                                    <td style='width: 175px;'>".$make."</td>
                                    <td style='width: 200px;'>".$model."</td>
                                    <td style='width: 100px;'>".$trim."</td>
                                    <td style='width: 25px;'>".'<a href="mycarsprofile.php?id=' .$vid. '"><img src="images/document.png" width="33px" height="25px"></a>'."</td>
                                    <td style='width: 25px;'>".'<a href="soldvehicle.php?id=' .$vid. '"><img src="images/redx.png" width="33px" height="25px"></a>'."</td>
                                </tr>";

                    }

                    echo "</table>"

                ?>

            </div>

        </div>

    <?php include ("layout/footer.php"); ?>

    <!-- end .container -->
</div>

</body>
</html>

我知道我很容易接受SQL注入,而且我确定有一些我可以整理的东西。我正在努力解决这个问题,但首先我只想让它现在起作用,我可以稍后改进。

我还试过几次尝试移动db_connect的东西。例如,我只是将连接信息直接放入php页面而不是包含phpfunctions,它对页面没有任何影响 - 同样的问题。

更复杂的mysql_connect内容来自this link,但我已经尝试将其简化为我之前所知的工作:

<?php

    mysql_connect("mysql01", "mycaradmin", "secret") 
        or die(mysql_error()); 

    mysql_select_db("mycars") 
        or die(mysql_error()); 

?>

显然那是在我开始添加似乎没有在mysql中工作的东西之前所以当我将它直接添加到index.php中时我将mysql更改为mysqli但是当我这样做时它并没有甚至再给出标题或主信息部分,只显示背景。

我为这个冗长的问题道歉,但希望我提供了足够的信息让我朝着正确的方向前进。

提前致谢!

更新:

我根据mysqli_connect的php文档中的信息创建了一个测试页面,并且我获得了成功。

<?php

    $link = mysqli_connect("mysql01", "jeremy", "secret", "mycars");

    if (!$link) {
        echo "Error: Unable to connect to MySQL." . PHP_EOL;
        echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
        echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
        exit;
        }

    echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
    echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

    mysqli_close($link);

?>

我得到以下内容:

Success: A proper connection to MySQL was made! The my_db database is great. Host information: mysql01 via TCP/IP

1 个答案:

答案 0 :(得分:0)

这似乎是由mysql和mysqli命令之间的语法差异引起的。一旦我找到了mysqli语法的良好基础,页面就开始工作了。