Php database connection encoding settings

Source: Internet
Author: User
For php database connection encoding settings, I first run the PHP website locally. The environment has been properly matched and the database has been imported. an error occurs during IIS browsing. a prompt box is displayed, ". $ str."

This is the error. Is there any help.

Public function show_error ($ message = '', $ SQL = ''){
Echo" ";
Echo" Error message:
";
Echo"

";
Echo 'error cause: '. mysql_error ()."

";
Echo"

";
Echo "". $ message ."";
Echo"

";
Echo"
" . $sql . "
";
Echo"

";
Echo" ";
}


Reply to discussion (solution)

Post the code ....

Post the code ....

Can you help me? This problem occurred all morning.

Let's take a look at the figure. it doesn't feel like you think it is.

Let's take a look at your code. your error message does not clearly indicate the error.

Let's take a look at your code. your error message does not clearly indicate the error.

This is the code for database connection!


Class mysql {

Private $ db_host;
Private $ db_user;
Private $ db_pwd;
Private $ db_database;
Private $ conn;
Private $ SQL;
Private $ result;
Private $ coding;
Private $ show_error = true;

Public function _ construct ($ db_host = "localhost", $ db_user = "root", $ db_pwd = "admin", $ db_database = "likang ", $ coding = 'utf-8 '){
$ This-> db_host = $ db_host;
$ This-> db_user = $ db_user;
$ This-> db_pwd = $ db_pwd;
$ This-> db_database = $ db_database;
$ This-> coding = $ coding;
$ This-> connect ();
}

Private function connect (){

$ This-> conn = @ mysql_connect ($ this-> db_host, $ this-> db_user, $ this-> db_pwd );
If (! $ This-> conn ){
If ($ this-> show_error ){
$ This-> show_error ('error prompt: failed to connect to the database! ');
}
}

If (! @ Mysql_select_db ($ this-> db_database, $ this-> conn )){
If ($ this-> show_error ){
$ This-> show_error ('error prompt: failed to open the database! ');
}
}

If (! @ Mysql_query ("set names $ this-> coding ")){
If ($ this-> show_error ){
$ This-> show_error ('error prompt: failed to set the encoding! ');
}
}
}

Public function query ($ SQL ){
$ This-> SQL = $ SQL;
$ Result = mysql_query ($ this-> SQL, $ this-> conn );
If (! $ Result ){
$ This-> show_error ('wrong SQL statement: ', $ this-> SQL );
} Else {
Return $ this-> result = $ result;
}
}

Public function close ()
{
Return mysql_close ();
} // Close the database connection


Public function show_databases (){
$ This-> query ("show databases ");
Echo 'existing database: '. mysql_num_rows ($ this-> result );
Echo"
";
$ I = 1;
While ($ row = mysql_fetch_array ($ this-> result )){
Echo "$ I $ row [Database]"."
";
$ I ++;
}
}

Public function show_tables (){
$ This-> query ("show tables ");
Echo "database {$ this-> db_database} total". mysql_num_rows ($ this-> result). "table :";
Echo"
";
$ Column_name = "Tables_in _". $ this-> db_database;
$ I = 1;
While ($ row = mysql_fetch_array ($ this-> result )){
Echo "$ I $ row [$ column_name]"."
";
$ I ++;
}
}

Public function fetch_array ($ result = ''){
If ($ this-> result ){
Return mysql_fetch_array ($ this-> result );
} Else {
Return mysql_fetch_array ($ result );
}
}

Public function findall ($ table, $ field = '*'){
Return $ this-> query ("SELECT $ field FROM $ table ");
}

Public function delete ($ table, $ condition ){
Return $ this-> query ("delete from $ table WHERE $ condition ");
}

Public function insert ($ table, $ field, $ value ){
$ I = $ this-> query ("INSERT INTO $ table ($ field) VALUES ('$ value ')");
Return $ I;
}

Public function update ($ table, $ update_content, $ condition ){
// Echo "UPDATE $ table SET $ update_content WHERE $ condition ";

Return $ this-> query ("UPDATE $ table SET $ update_content WHERE $ condition ");

}

Public function insert_id (){
Return mysql_insert_id ();
}

Public function num_rows (){
If ($ this-> result = null ){
If ($ this-> show_error ){
$ This-> show_error ('SQL statement error',' check whether the query () method is used and the resource identifier is returned? ');
}
} Else {
Return mysql_num_rows ($ this-> result );
}
}

Public function num_fields ($ table ){
$ This-> query ("select * from $ table ");
Echo"
";
Echo 'field count: '. $ total = mysql_num_fields ($ this-> result );
Echo"

";  
for ($i = 0; $i < $total; $i++) {
print_r(mysql_fetch_field($this->result, $i));
}
echo "
";
Echo"
";
}

Public function show_error ($ message = '', $ SQL = ''){
Echo" ";
Echo" Error message:
";
Echo"

";
Echo 'error cause: '. mysql_error ()."

";
Echo"

";
Echo "". $ message ."";
Echo"

";
Echo"
" . $sql . "
";
Echo"

";
Echo" ";
}


}

?>

Let's take a look at the figure. it doesn't feel like you think it is.

When I click index. php, the database connection code and two pop-up window ". $ str." are displayed. the code I pasted is displayed in red.
Public function show_error ($ message = '', $ SQL = ''){
Echo"

";
Echo" Error message:
";
Echo"

";
Echo 'error cause: '. mysql_error ()."

";
Echo"

";
Echo "". $ message ."";
Echo"

";
Echo"
" . $sql . "
";
Echo"

";
Echo" ";

After clicking OK, the page cannot be found.

This is the PHP configuration environment. mysql has no value. is it related to this? Wordpress phpMyAdmin is installed in these places.

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.