Mysql connection succeeded, but the prompt mysql_query is not defined

Source: Internet
Author: User
Mysql connection is successful, but the message mysql_query is not defined. mysql php

Scenario description:
Query databases on two servers and extract user data.
① The data list is displayed successfully.
 GetAddrPerson ($ _ SESSION ['uid']); // personal address book $ dataPers = (empty ($ addrPersons ['addrone'])? Array (): json_decode (base64_decode ($ addrPersons ['addrperson']), true); // $ addrPersons array (); # get the company address book $ stafflists = $ mysql-> getDomainUserList ($ domain); $ stafflists _ = $ mysql _-> getDomainUserList ($ domain ); debug (count ($ stafflists); // 29 debug (count ($ stafflists _); // 57

② Provide a search, and extract user data from the two servers on a separate search page, and filter the data based on keywords.
At this time, PHP terminates, Fatal error: Call to undefined function mysql_query ()

 GetAddrPerson ($ _ SESSION ['uid']); // individual $ dataPers = (empty ($ addrPersons ['addrperson'])? Array (): json_decode (base64_decode ($ addrPersons ['addrperson']), true ); // $ addrPersons null # obtain the company address book $ stafflists = $ mysql-> getDomainUserList ($ domain); // $ stafflists _ = $ othersql-> getDomainUserList ($ domain ); debug ($ stafflists); exit; // debug ($ stafflists _);


Which step may be wrong?


Reply to discussion (solution)

In the code you posted, no mysql_query is displayed.
You can only troubleshoot the error based on the row number indicated by the error message

In php code, the database password should be the same as the password in the database on the computer.

Require_once (dirname (_ FILE __). "/.. /classes/mode/mysql_mode_class.php "); require_once (dirname (_ FILE __). "/.. /classes/mode/mysql_list_class.php "); // These two rows are also contained in the header. php contains // The execution functions in these two classes are the same class MySqlList {// SQL paramspublic $ 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 ifif (empty ($ config )) die ("An error occurred while reading MySql configuration. "); $ 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 ("server connection failed :". mysql_error ();} $ conn = mysql_select_db ($ this-> database, $ connect) or die ("database connection failed!
"); Mysql_query (" set names utf8 "); return $ connect;} // execute sqlfunction querySql ($ SQL, $ array = 2, $ fail = false, $ succe = false, $ suc_href = false, $ type = MYSQL_ASSOC) {global $ webpost; $ result = mysql_query ($ SQL, $ this-> connect ()); // prompt to terminate if (! $ Result) die ("SQL: {$ SQL}
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 () ;}# obtain the user data function of another database 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 );}}

Where is the problem?

Except mysql_query, no error is reported for other mysql functions.
Mysql extension installation (compilation) error only

However, after extracting user data, the list is displayed.
This problem occurs only on a separate search page.

You provide too little information
Spelling errors in some applications are not excluded.

It was finally found out because the $ _ SESSION was not obtained on a separate search page.
However, I added session_start () and obtained the search page content from the previous list page through $. ajax.
Why is the $ _ SESSION on the search page empty?

Check the list of objects returned by get_included_files in the $ _ SESSION empty program.

Generally, session_start () should be placed in a global public file.
Besides, php 5.4 also checks whether the function has been executed. if it has been executed, a warning is generated.

The problem is solved.
Cause: The position of header () and session_start () on the include page of the search page is incorrect. Just remove the header from the contained page.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.