PHP MySQL functies
- Vorige pagina PHP Math
- Volgende pagina PHP MySQLi
Introductie tot PHP MySQL
MySQL-functies geven u toegang tot de MySQL-databankserver.
Installatie
Om de functies van deze klasse soepel te kunnen gebruiken, moet MySQL-ondersteuning worden toegevoegd bij het compileren van PHP.
Gebruik alleen de configuratieoptie --with-mysql[=DIR] bij het compileren, waarbij de optionele [DIR] de installatiemap van MySQL aanduidt.
Hoewel deze MySQL-uitbreidingsbibliotheek compatibel is met MySQL 4.1.0 en latere versies, ondersteunt het geen extra functies die deze versies bieden. Gebruik de MySQLi-uitbreidingsbibliotheek om deze functies te gebruiken.
Als u zowel de mysql-uitbreidingsbibliotheek als de mysqli-uitbreidingsbibliotheek wilt installeren, moet u dezelfde clientbibliotheek gebruiken om conflicten te voorkomen.
Installatie op het Linux-systeem
PHP 4
De optie --with-mysql is standaard ingeschakeld. Dit standaardgedrag kan worden uitgeschakeld met de configuratieoptie --without-mysql. Als MySQL wordt ingeschakeld zonder installatiemap op te geven, gebruikt PHP de gebonden MySQL-clientverbindingbibliotheek.
Gebruik niet de gebonden bibliotheek voor andere toepassingen die MySQL gebruiken (bijvoorbeeld auth-mysql), maar specificeer de installatiemap van MySQL, zoals hieronder: --with-mysql=/pad/naar/mysql. Dit dwingt PHP om de clientverbindingbibliotheek die bij MySQL wordt geïnstalleerd te gebruiken, waardoor conflicten kunnen worden voorkomen.
PHP 5+
MySQL is standaard niet ingeschakeld en heeft geen gebonden MySQL-bibliotheek. Gebruik de configuratieoptie --with-mysql[=DIR] om ondersteuning voor MySQL toe te voegen. Het is mogelijk om MySQL Download de headerbestanden en bibliotheken.
Installatie op het Windows-systeem
PHP 4
De PHP MySQL-uitbreiding is geïntegreerd in PHP.
PHP 5+
MySQL is standaard niet ingeschakeld, dus moet php_mysql.dll dynamische koppelingsbibliotheek in php.ini worden geactiveerd. Bovendien heeft PHP toegang nodig tot de MySQL clientverbindingbibliotheek. De Windows-uitgave van PHP bevat een libmysql.dll, zodat PHP met MySQL kan communiceren, moet dit bestand in het systeempad PATH van Windows worden geplaatst.
Om elke PHP-uitbreidingsbibliotheek (bijvoorbeeld php_mysql.dll) te activeren, moet de PHP-instructie extension_dir worden ingesteld op de map van de PHP-uitbreidingsbibliotheek. Een voorbeeld van een waarde voor extension_dir onder PHP 5 is c:\php\ext.
Opmerking:Als er een fout zoals hierboven wordt weergegeven bij het starten van de webserver: "Unable to load dynamic library './php_mysql.dll'" is dit omdat het systeem php_mysql.dll en / of libmysql.dll niet kan vinden.
Run-time configuratie
Het gedrag van MySQL-functies wordt beïnvloed door de instellingen in php.ini.
MySQL-configuratieopties:
Naam | Standaard | Beschrijving | Aanpasbaar |
---|---|---|---|
mysql.allow_persistent | "1" | Of MySQL-persistente verbindingen toegestaan zijn. | PHP_INI_SYSTEM |
mysql.max_persistent | "-1" | Maximaal aantal persistente verbindingen per proces. | PHP_INI_SYSTEM |
mysql.max_links | "-1" | Maximaal aantal verbindingen per proces, inclusief persistente verbindingen. | PHP_INI_SYSTEM |
mysql.trace_mode | "0" | Volgmodus. Beschikbaar vanaf PHP 4.3.0. | PHP_INI_ALL |
mysql.default_port | NULL | Specificeer de standaard TCP-poort voor de verbinding met de database. | PHP_INI_ALL |
mysql.default_socket | NULL | Standaard socketnaam. Beschikbaar vanaf PHP 4.0.1. | PHP_INI_ALL |
mysql.default_host | NULL | Standaard serveradres. Niet geschikt voor SQL-beveiligingsmodus. | PHP_INI_ALL |
mysql.default_user | NULL | Standaardgebruikte gebruikersnaam. Niet geschikt voor SQL-beveiligingsmodus. | PHP_INI_ALL |
mysql.default_password | NULL | Standaardgebruikte wachtwoord. Niet geschikt voor SQL-beveiligingsmodus. | PHP_INI_ALL |
mysql.connect_timeout | "60" | Seconden van connectietijd-out. | PHP_INI_ALL |
Soort bronnen
Twee soorten bronnen worden gebruikt in het MySQL-module. De eerste is de verbindingshandle van de database en de tweede is het resultaat van de SQL-query.
PHP MySQL functies
PHP:Indicate the earliest PHP version that supports this function.
Function | Beschrijving | PHP |
---|---|---|
mysql_affected_rows() | Get the number of rows affected by the previous MySQL operation. | 3 |
mysql_change_user() | Not recommended. Change the logged-in user in the active connection | 3 |
mysql_client_encoding() | Return the name of the character set of the current connection | 4 |
mysql_close() | Close a non-persistent MySQL connection. | 3 |
mysql_connect() | Open a non-persistent MySQL connection. | 3 |
mysql_create_db() | Not recommended. Create a new MySQL database. Use mysql_query() instead. | 3 |
mysql_data_seek() | Move the record pointer. | 3 |
mysql_db_name() | Return the database name from the call to mysql_list_dbs(). | 3 |
mysql_db_query() |
Not recommended. Send a MySQL query. Use mysql_select_db() and mysql_query() instead. |
3 |
mysql_drop_db() |
Not recommended. Drop (delete) a MySQL database. Use mysql_select_db() and mysql_query() instead. Gebruik mysql_query() in plaats daarvan. |
3 |
mysql_errno() | Return the numeric code of the error information in the last MySQL operation. | 3 |
mysql_error() | Return the text error message generated by the last MySQL operation. | 3 |
mysql_escape_string() |
Not recommended. Escape a string for mysql_query. Use mysql_real_escape_string() instead. |
4 |
mysql_fetch_array() | Get a row from the result set as an associative array, or a numeric array, or both. | 3 |
mysql_fetch_assoc() | Get a row from the result set as an associative array. | 4 |
mysql_fetch_field() | Get column information from the result set and return it as an object. | 3 |
mysql_fetch_lengths() | Get the length of the content of each field in the result set. | 3 |
mysql_fetch_object() | Get a row from the result set as an object. | 3 |
mysql_fetch_row() | Get a row from the result set as a numeric array. | 3 |
mysql_field_flags() | Get the flags associated with the specified field from the result. | 3 |
mysql_field_len() | Return the length of the specified field. | 3 |
mysql_field_name() | Haal de naam van het specifieke veld in de resultaten op. | 3 |
mysql_field_seek() | Stel de cursor in de resultatenreeks in op de opgegeven veldafstand. | 3 |
mysql_field_table() | Haal de naam van de tabel waarin het specifieke veld zich bevindt op. | 3 |
mysql_field_type() | Haal het type van het specifieke veld in de resultatenreeks op. | 3 |
mysql_free_result() | Vrijgeef de geheugenruimte van de resultaten. | 3 |
mysql_get_client_info() | Haal de MySQL-clientinformatie op. | 4 |
mysql_get_host_info() | Haal de MySQL-hostinformatie op. | 4 |
mysql_get_proto_info() | Haal de MySQL-protocolinformatie op. | 4 |
mysql_get_server_info() | Haal de informatie van de MySQL-server op. | 4 |
mysql_info() | Haal de informatie van de laatste query op. | 4 |
mysql_insert_id() | Haal de ID op die is gegenereerd door de laatste INSERT-operatie. | 3 |
mysql_list_dbs() | Lijst alle databases in de MySQL-server. | 3 |
mysql_list_fields() |
Niet aanbevolen. Lijst de velden in de MySQL-resultaten. Gebruik mysql_query() in plaats daarvan. |
3 |
mysql_list_processes() | Lijst de MySQL-processen. | 4 |
mysql_list_tables() |
Niet aanbevolen. Lijst de tabellen in de MySQL-database. Gebruik mysql_query() in plaats daarvan. |
3 |
mysql_num_fields() | Haal het aantal velden in de resultatenreeks op. | 3 |
mysql_num_rows() | Haal het aantal rijen in de resultatenreeks op. | 3 |
mysql_pconnect() | Maak een duurzame verbinding naar de MySQL-server. | 3 |
mysql_ping() | Ping een serververbinding, als er geen verbinding is, maak een nieuwe verbinding. | 4 |
mysql_query() | Verstuur een MySQL-query. | 3 |
mysql_real_escape_string() | Escape specifieke karakters in de te gebruiken SQL-string. | 4 |
mysql_result() | Haal de resultaatgegevens op. | 3 |
mysql_select_db() | Selecteer de MySQL-database. | 3 |
mysql_stat() | Haal de huidige systeemstatus op. | 4 |
mysql_tablename() | Niet aanbevolen. Haal de tabelnaam op. Gebruik mysql_query() in plaats daarvan. | 3 |
mysql_thread_id() | Geef de ID van de huidige thread terug. | 4 |
mysql_unbuffered_query() | Stuur een SQL query naar MySQL (zonder resultaat te verkrijgen / op te slaan). | 4 |
PHP MySQL constanten
In versies na PHP 4.3.0 is het toegestaan om meer client markers te specificeren in de mysql_connect() functie en de mysql_pconnect() functie:
PHP:Indiceert de oudste PHP versie die de constante ondersteunt.
Constanten | Beschrijving | PHP |
---|---|---|
MYSQL_CLIENT_COMPRESS | Gebruik gecomprimeerde communicatieprotocol. | 4.3 |
MYSQL_CLIENT_IGNORE_SPACE | Laat een lege ruimte achter achter de functienaam toe. | 4.3 |
MYSQL_CLIENT_INTERACTIVE | De inactiviteitstijd die wordt toegestaan voordat de verbinding wordt gesloten. | 4.3 |
MYSQL_CLIENT_SSL | Gebruik SSL encryptie (alleen beschikbaar voor MySQL client library versie 4+). | 4.3 |
De mysql_fetch_array() functie gebruikt een constante om het type van de teruggegeven array aan te geven:
Constanten | Beschrijving | PHP |
---|---|---|
MYSQL_ASSOC | De teruggegeven data kolommen gebruiken veldnamen als array indices. | |
MYSQL_BOTH | De teruggegeven data kolommen gebruiken veldnamen en numerieke indices als array indices. | |
MYSQL_NUM |
De teruggegeven data kolommen gebruiken numerieke indices als array indices. Index begint bij 0, wat de eerste teruggegeven kolom aangeeft. |
- Vorige pagina PHP Math
- Volgende pagina PHP MySQLi