mysql php
情景描述:查询两台服务器上的数据库,提取用户数据。
① 将数据列表显示,已成功
<?php/* Filename[book.php] */require_once("header.php");#连接另一台数据库$mysql_ = new MySqlList();#获取通讯录$addrPersons= empty($_SESSION['uid'])?null:$mysql->getAddrPerson($_SESSION['uid']); //个人//个人通讯录$dataPers = (empty($addrPersons['addrperson']))?array():json_decode(base64_decode($addrPersons['addrperson']),true);//$addrPersons array();#获取公司通讯录$stafflists = $mysql->getDomainUserList($domain);$stafflists_ = $mysql_->getDomainUserList($domain);debug(count($stafflists)); //29debug(count($stafflists_)); //57
② 提供搜索,在单独的搜索页再次提取两台服务器上的用户数据,并根据关键词进行过滤。
此时PHP终止,Fatal error: Call to undefined function mysql_query()
<?php/* Filename[book_search.php] */date_default_timezone_set('PRC');Header("content=text/html; charset=UTF-8");session_start();require_once (dirname(__FILE__) . "/../classes/action/initialize.php");require_once (dirname(__FILE__) . "/../classes/mode/xmlparse.inc");require_once (dirname(__FILE__) . "/../classes/mode/mysql_mode_class.php");require_once (dirname(__FILE__) . "/../classes/mode/mysql_list_class.php");#连接本地数据库$mysql = new MySqlModeMail();#连接另一台数据库//$othersql = new MySqlList();#获取通讯录$addrPersons= empty($_SESSION['uid'])?null:$mysql->getAddrPerson($_SESSION['uid']); //个人$dataPers = (empty($addrPersons['addrperson']))?array():json_decode(base64_decode($addrPersons['addrperson']),true);//$addrPersons null#获取公司通讯录$stafflists = $mysql->getDomainUserList($domain);//$stafflists_ = $othersql->getDomainUserList($domain);debug($stafflists);exit;//debug($stafflists_);
可能是哪一步出错?
回复讨论(解决方案)
在你贴出的代码中,没有看到 mysql_query
你只能根据错误信息指示的行号排查错误
php代码中数据库的密码要和电脑里的数据库中的密码一样
require_once (dirname(__FILE__) . "/../classes/mode/mysql_mode_class.php");require_once (dirname(__FILE__) . "/../classes/mode/mysql_list_class.php");//这两行也有在header.php中包含//这两个类中的执行函数是一样的 class MySqlList { //sql params public $server; public $username; public $password; public $database; public $code; function MySqlList(){ global $webpost;// include("xmlparse.inc"); $sqlist = parse_xml_config($webpost['path']['sqlist'],"sqlist"); if(!empty($sqlist) && is_array($sqlist)){ foreach($sqlist['list'] as $list){ if(strcmp($list['server'],$_SERVER['SERVER_ADDR'])){ $config = $list; } }//end for }//end if if(empty($config)) die("读取MySql配置出错。"); $this->server = $config['server']; $this->username = $config['username']; $this->password = $config['password']; $this->database = $config['database']; } //connect sql function connect(){ $connect = mysql_connect($this->server, $this->username, $this->password); if (!$connect){ die("服务器连接失败:".mysql_error()); } $conn = mysql_select_db($this->database,$connect) or die("数据库连接失败!<br/>"); mysql_query("set names utf8"); return $connect; } //execute sql function querySql($sql,$array=2,$fail=false,$succe=false,$suc_href=false,$type=MYSQL_ASSOC){ global $webpost; $result = mysql_query($sql,$this->connect()); //提示在这里终止 if(!$result) die("SQL: {$sql} <br>Error: " . mysql_error() ); if (mysql_affected_rows() >0){// write_sys_log("success SQL:".$sql); switch($array){ case 1: $arry = array(); while($arr = @mysql_fetch_array($result,$type)){ array_push($arry,$arr); } return $arry; case 2: $arr = @mysql_fetch_array($result,$type); return $arr; default: return 1; } }elseif(mysql_affected_rows() == 0 && !mysql_errno()){// write_sys_log("empty SQL:".$sql); return false; }elseif(mysql_errno()){// write_sys_log("failed SQL:".$sql); return 0; } mysql_close(); } #获取另一台数据库的用户数据 function getDomainUserList($domain){ $sql = "SELECT m.id,m.did,m.code,username,realname,domain FROM table_a m ". "JOIN table_b d ON m.did=d.id WHERE domain='{$domain}'"; return $this->querySql($sql,1); } }
思路上大概哪里有问题?
除 mysql_query 外,其他 mysql 族函数均没有报错
只能说 mysql 扩展安装(编译)错误
但是,我在提取用户数据后,是可以列表显示的。
只是在单独的搜索页却出现这个问题。
你提供的信息太少
不排除个别应用中单词拼写错误
终于排查出来了,是因为单独的搜索页没有获取到$_SESSION。
但是我加session_start()了,而且是由前面的列表页,通过$.ajax获取搜索页的内容。
为什么搜索页的$_SESSION是空的?
在 $_SESSION 为空的程序中检查 get_included_files 返回的文件列表
通常 session_start() 宜放在全局的公共文件中
况且 php 5.4 还会检查该函数是否被执行过,如执行过将会产生警告信息
问题解决了。
原因:在搜索页的包含页中,header()和session_start()的位置搞错了。把包含页中的header注掉就好了。

Calculating the total number of elements in a PHP multidimensional array can be done using recursive or iterative methods. 1. The recursive method counts by traversing the array and recursively processing nested arrays. 2. The iterative method uses the stack to simulate recursion to avoid depth problems. 3. The array_walk_recursive function can also be implemented, but it requires manual counting.

In PHP, the characteristic of a do-while loop is to ensure that the loop body is executed at least once, and then decide whether to continue the loop based on the conditions. 1) It executes the loop body before conditional checking, suitable for scenarios where operations need to be performed at least once, such as user input verification and menu systems. 2) However, the syntax of the do-while loop can cause confusion among newbies and may add unnecessary performance overhead.

Efficient hashing strings in PHP can use the following methods: 1. Use the md5 function for fast hashing, but is not suitable for password storage. 2. Use the sha256 function to improve security. 3. Use the password_hash function to process passwords to provide the highest security and convenience.

Implementing an array sliding window in PHP can be done by functions slideWindow and slideWindowAverage. 1. Use the slideWindow function to split an array into a fixed-size subarray. 2. Use the slideWindowAverage function to calculate the average value in each window. 3. For real-time data streams, asynchronous processing and outlier detection can be used using ReactPHP.

The __clone method in PHP is used to perform custom operations when object cloning. When cloning an object using the clone keyword, if the object has a __clone method, the method will be automatically called, allowing customized processing during the cloning process, such as resetting the reference type attribute to ensure the independence of the cloned object.

In PHP, goto statements are used to unconditionally jump to specific tags in the program. 1) It can simplify the processing of complex nested loops or conditional statements, but 2) Using goto may make the code difficult to understand and maintain, and 3) It is recommended to give priority to the use of structured control statements. Overall, goto should be used with caution and best practices are followed to ensure the readability and maintainability of the code.

In PHP, data statistics can be achieved by using built-in functions, custom functions, and third-party libraries. 1) Use built-in functions such as array_sum() and count() to perform basic statistics. 2) Write custom functions to calculate complex statistics such as medians. 3) Use the PHP-ML library to perform advanced statistical analysis. Through these methods, data statistics can be performed efficiently.

Yes, anonymous functions in PHP refer to functions without names. They can be passed as parameters to other functions and as return values of functions, making the code more flexible and efficient. When using anonymous functions, you need to pay attention to scope and performance issues.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Atom editor mac version download
The most popular open source editor

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
