首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Dreamweaver中使用PHP和MySQLi将网页连接到数据库

问如何在Dreamweaver中使用PHP和MySQLi将网页连接到数据库
EN

Stack Overflow用户
提问于 2015-06-07 10:35:15
回答 1查看 682关注 0票数 0

我正在使用Dreamweaver来生成用于连接到数据库的PHP和SQLi代码。我已经成功地做到了这一点,但是我不断地得到以下错误:

代码语言:javascript
复制
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\Maseno\Site\Template.php on line 32

Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\wamp\www\Maseno\Site\Template.php on line 34

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\wamp\www\Maseno\Site\Template.php on line 34,

这是我的源代码:

代码语言:javascript
复制
<?php require_once('../../Connections/connect.php'); ?>
<?php

if (!function_exists("GetSQLValueString")) {
  function GetSQLValueString($theValue, $theType, $theDefinedValue = "", 
                             $theNotDefinedValue = "") {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

    $theValue = function_exists("mysql_real_escape_string") ?  
      mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

    switch ($theType) {
      case "text":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;    
      case "long":
      case "int":
        $theValue = ($theValue != "") ? intval($theValue) : "NULL";
        break;
      case "double":
        $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
        break;
      case "date":
        $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
        break;
      case "defined":
        $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
        break;
    }
    return $theValue;
  }
}

mysqli_select_db($database_connect, $connect);
$query_Users = "SELECT * FROM students";
$Users = mysqli_query($query_Users, $connect) or die(mysqli_error());
$row_Users = mysqli_fetch_assoc($Users);
$totalRows_Users = mysqli_num_rows($Users);

?>
EN

回答 1

Stack Overflow用户

发布于 2015-06-07 12:16:26

您正在使用mysql_和mysqli_ 函数。您应该只使用mysqli或PDO。

mysql_函数已不再推荐使用.

mysqli_函数与mysql_函数有些不同。大多数时候,您需要添加一个额外的参数:连接资源。

例如:

代码语言:javascript
复制
$link = mysqli_connect("localhost", "my_user", "my_password", "my_database");
mysqli_query($link, "SHOW TABLES");

只需用google "php “查找有关特定函数的信息。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30692522

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档