Home Database Mysql Tutorial MYSQL入门之二_PHP操作MYSQL_MySQL

MYSQL入门之二_PHP操作MYSQL_MySQL

Jun 01, 2016 pm 01:38 PM
local connection

bitsCN.com

MYSQL入门之二_PHP操作MYSQL

 

1.        本地连接MySQL    

 

              $con= mysql_connect("localhost", "root", "xxxxxx");

 

              if(!$con) {

 

                     die('Could not connect: ' .mysql_error());

 

              }else {

 

                     echo"Connect success
/n";

 

              }

 

2.        SAE连接MySQL

 

              $con =mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,

 

                            SAE_MYSQL_USER,SAE_MYSQL_PASS);

 

              if (!$con) {

 

                     die('Could not connect: ' .mysql_error());

 

              } else {

 

                     echo"Connect success
/n";

 

              }

 

              mysql_select_db(SAE_MYSQL_DB,$con);

 

3.        断开MySQL

 

              mysql_close($con);

 

4.        建立数据库

 

              $sql = "CREATE DATABASE IFNOT EXISTS $DATABASE_NAME";

 

              if(mysql_query($sql, $con)) {

 

                     echo "Database create success
/n";

 

              }else {

 

                     echo"Error creating database: " . mysql_error() ."
/n";

 

              }

 

5.        连接使用数据库

 

              mysql_select_db($DATABASE_NAME,$con);

 

6.        建立数据表

 

              $sql ="CREATE TABLE $TABLE_NAME (

 

                     namevarchar(80),

 

                     ageint

 

              )ENGINE=MyISAM DEFAULT CHARSET=utf8";

 

              if(mysql_query($sql,$con)) {

 

                     echo "Table create success
/n";

 

              }else {

 

                     echo"Error creating table: " . mysql_error() . "
/n";

 

              }

 

7.        查找数据

 

              $sql= "SELECT * FROM $TABLE_NAME where name like /"%$INPUT%/"";

 

              $result= mysql_query($sql,$con);

 

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

 

                     echo$row['name'] . " " . $row['age'];

 

                     echo"
";

 

              }

 

8.        设置字符集(设置之后的sql操作基于utf8字符集)

mysql_query("SET NAMES 'utf8'");

mysql_query("SET CHARACTER_SET_CLIENT=utf8");

mysql_query("SET CHARACTER_SET_RESULTS=utf8");

 

bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the problem that DHCP is not enabled in the local connection. Recommended solutions to the problem that the computer cannot access the Internet and prompts that the DHCP service is not enabled. How to solve the problem that DHCP is not enabled in the local connection. Recommended solutions to the problem that the computer cannot access the Internet and prompts that the DHCP service is not enabled. Mar 13, 2024 pm 12:07 PM

When many users use computers to connect to Ethernet, they will see the prompt "DHCP is not enabled" and don't know what to do. This is because the DHCP function is not enabled on the router. This article teaches you how to solve this problem. 1. Check the login information. To solve the problem of "DHCP is not enabled on the Ethernet", you need to log in to the router first. When logging in to a router, you usually need to obtain the router's gateway, username, and password information. This information is usually marked on the back of the router. The IP of the router is the so-called gateway address. The default gateway address of some routers is 192.168.1.1 or 192.168.0.1. The login account generally defaults to admin and the password is admin or 123456. 2. Log in to router management

How to create a local connection in win11 How to create a local connection in win11 Jun 29, 2023 pm 12:55 PM

How to create a local connection in win11? After upgrading to the win11 system, some friends found that some functions could not be used normally. When some friends used local connection, they found that they could not connect normally. If they could not connect normally, they would not be able to access the Internet. So how should we solve it. The editor below has compiled the steps to create a local connection in win11. If you are interested, follow the editor to read below! Steps to create a local connection in win11: 1. Click the desktop start menu to open the settings panel, as shown in the figure. 2. Find the Network and Internet options, as shown in the figure. 3. Click the Set Dial-up Connection button, as shown in the figure. 4. Click Set New Connection Options under this column, as shown in the figure. 5. Finally click Set New Network Diagram

Delete redundant local connections in Win7 system 2 Delete redundant local connections in Win7 system 2 Jul 19, 2023 pm 06:21 PM

When checking the computer network connection of the Win7 system, sometimes you will find that in addition to the local connection, there is also a local connection 2. After understanding, we know that this is a redundant network card local connection address. Due to the existence of local connection 2, sometimes the local connection cannot be connected and therefore cannot access the Internet. How do we remove redundant local area connection 2? Win7 system deletes redundant local connections 2. 1. Click the Start menu, search for Run and press the Enter key or directly press the Windows key (window) + R key to open the Run dialog box; 2. Enter regedit in the Run dialog box, and Press the OK key; 3. In the registry editor, expand to HKEY_LOCAL_MCHINE\SYSTEM\Curentcontrol

What to do if there is no local connection in win7 system What to do if there is no local connection in win7 system Jun 29, 2023 pm 01:46 PM

What should I do if there is no local connection in win7 system? Win7 system cannot make local connection. How to solve the problem and share the tutorial. After reinstalling win7 system or just installing a new system on the computer, the user finds that his computer cannot connect to the network. Many users will encounter this situation. The reason is that the computer does not have the corresponding driver, and they need to update it or download the driver. Win7 system cannot perform local connection solution operation tutorial sharing 1. If you find that there is no exclamation mark and question mark in front of the network card driver in the device manager, and the driver is normal, then you should consider the error of the network connection management service program. 2. Press and hold the Win key + R key to open the run window. 3. In order

Where is the local connection in win7? Where is the local connection in win7? Dec 23, 2023 pm 10:59 PM

Although many friends have been using computers for a long time, they don’t know where the local connection is in Windows 7. Today, the editor will bring you how to open the local connection in Windows 7! Let’s take a look. How to open local connection on Win7 computer: 1. First, click "Network" on the Win7 desktop to enter the network settings. 2. Click "Network and Sharing Center" at the top. 3. Then click "Change Adapter Settings" on the left. 4. Click "Change Adapter" settings to find the local connection. (The above is all the content about where is the local connection in win7 brought by the editor! If the above content is helpful to your problem, please pay attention to this site, we will bring you continuous high-quality content)

How to solve the problem that the local connection does not have a valid IP configuration How to solve the problem that the local connection does not have a valid IP configuration Aug 17, 2023 am 10:51 AM

The solutions to the local connection without valid IP configuration are: 1. Restart the network device; 2. Set to automatically obtain an IP address; 3. Disable and re-enable the local connection; 4. Refresh the IP configuration; 5. Check the network cable and physical Connect; 6. Reset the network adapter.

What should I do if the local connection is missing? What should I do if the local connection is missing? Mar 07, 2023 pm 02:23 PM

Solution to the missing local connection: 1. Enter the device manager, click on the network adapter, view the network card driver "Realtek PCle GBE Family Controller", and then reinstall the network card driver; 2. Press the "win+R" key to open Run and enter "regsvr32 netshell.dll", just set the network connection service.

How to restore local connection missing in win7 How to restore local connection missing in win7 Jul 02, 2023 pm 04:17 PM

How to restore local connection lost in win7? When using win7, some friends find that the local connection is missing. How to retrieve the local connection in this case? Many friends don't know how to retrieve it. Many friends don’t know how to operate it. The editor has compiled the method to restore the local connection in Windows 7 system. If you are interested, follow the editor to take a look below! Method to restore local connection in Windows 7 system 1. Right-click on the computer and click Properties. As shown in the figure: 2. A dialog box pops up and click Device Manager. As shown in the figure: 3. A dialog box pops up and expand the network adapter. As shown in the figure: 4. Right-click on RealtekPCleGBEFamilyController. If

See all articles