Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
MySQLi Articles
Page 3 of 341
Write an example to establish MySQL database connection using PHP script?
In PHP, you can establish a MySQL database connection using MySQLi or PDO extensions. The old mysql_connect() function is deprecated and should be avoided. Here are modern approaches to connect to MySQL database. Using MySQLi (Procedural) The MySQLi extension provides an interface to access MySQL databases − Using MySQLi (Object-Oriented) The object-oriented approach provides better code organization − Using PDO PDO (PHP Data Objects) provides a database-agnostic interface − Comparison Method Object-Oriented Prepared Statements Database Support ...
Read MoreWhich PHP function is used to disconnect from MySQL database connection?
PHP provides the mysql_close() function to disconnect from a MySQL database connection. This function takes a single parameter, which is a connection resource returned by the mysql_connect() function. Syntax bool mysql_close ( resource $link_identifier ); Here, if a resource is not specified, then the last opened database connection is closed. This function returns true if it closes the connection successfully, otherwise it returns false. Example The following example shows how to connect to and disconnect from a MySQL database − Important Note Deprecated Functions: The mysql_close() function ...
Read MoreDifference between Static SQL and Dynamic SQL
Static SQL and Dynamic SQL are two approaches to writing SQL statements in applications. Static SQL uses fixed, hard-coded queries known at compile time, while Dynamic SQL constructs queries at runtime based on user input or program logic. Static SQL Static SQL refers to SQL statements that are fixed and hard-coded into the application. Since the queries are known at compile time, they can be pre-analyzed, optimized, and do not require special security handling. Example -- Static SQL: query is fixed at compile time SELECT name, salary FROM employees WHERE department = 'Engineering'; ...
Read MoreDifference between MySQL and SQL Server
Both MySQL and SQL Server are relational database management systems (RDBMS) that use SQL for querying and managing data. MySQL is open source and owned by Oracle, whereas SQL Server is a licensed commercial product developed by Microsoft. MySQL MySQL is an open-source RDBMS that is widely used in web applications. It is free to use under the GPL license, lightweight in storage requirements, and runs on multiple platforms including Linux, Windows, and macOS. MySQL is the database behind many popular platforms like WordPress, Facebook, and Twitter. SQL Server SQL Server (Microsoft SQL Server) is a ...
Read MoreHow to display 3 random values from MySQL table?
To display random values from a MySQL table, use the RAND() function in the ORDER BY clause to shuffle the rows randomly, and LIMIT to restrict the number of results. The general syntax is − SELECT yourColumnName FROM yourTableName ORDER BY RAND() LIMIT 3; Creating the Demo Table Let us first create a table and insert some records − CREATE TABLE DemoTable646 ( Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, FirstName VARCHAR(100) ); INSERT INTO DemoTable646 (FirstName) VALUES ('John'); INSERT INTO DemoTable646 (FirstName) VALUES ('Bob'); INSERT INTO DemoTable646 (FirstName) VALUES ...
Read MoreSearching multiple columns for a row match in MySQL
To search multiple columns for a row match in MySQL, you can use the UNION operator. UNION combines the result sets of two or more SELECT statements into a single result, automatically removing duplicate rows. This is useful when you want to search different columns for different criteria and merge the results together. Creating the Demo Table Let us first create a table and insert some records − CREATE TABLE DemoTable645 ( Id INT, FirstName VARCHAR(100) ); INSERT INTO DemoTable645 VALUES (100, 'Chris'); INSERT INTO DemoTable645 VALUES (101, 'Robert'); INSERT INTO DemoTable645 ...
Read MoreHow to convert JS date time to MySQL datetime?
We can convert JS date time to MySQL datetime with the help of toISOString() function.Let us see an example of JavaScript.Example Web Page Design document.writeln(new Date().toISOString().slice(0, 19).replace('T', ' ')); Current Date is displayed above... OutputThe following is the output.2018-11-23 11:14:38 Current Date is displayed above...
Read MoreCount the number of columns in a MySQL table with Java
In this article, we will learn how to count the number of columns in a MySQL table using JDBC. We will be using the ResultSetMetaData to get details of the table by using simple examples. What is ResultSetMetaData? The ResultSetMetaData is an interface that is present in the java.sql package. Using ResultSetMetaData, we can get information about the table, for example, what are the column names of each and every table, and how many columns are there?. To create the object for ResultSet: ResultSet rs=st.executeQuery("Select * from Student"); The executeQuery method writes the records, which are then stored in the ...
Read MoreWhat is the difference between CHAR and NCHAR in MySQL?
In MySQL, both CHAR and NCHAR are ASCII character data types used for storing text data, but they differ significantly in terms of storage, data representation, and performance. CHAR and NCHAR columns can have different collations, determining how strings are compared and sorted. The CHAR type typically uses the collation associated with its specified character set. On the other hand, NCHAR is intended for Unicode data and typically uses a collation that can handle Unicode characters, ensuring proper sorting and comparison. Understanding 'CHAR' in MySQL The CHAR data type is primarily used to store ASCII character data. It is a ...
Read MoreWhat MySQL returns if I insert invalid value into ENUM?
If strict SQL mode is disabled and we insert an invalid value (which is not in the list of permitted enumeration values) into ENUM, MySQL will insert an empty string instead of throwing an error. If strict SQL mode is enabled, MySQL throws an error when inserting invalid value. Invalid values without strict SQL mode Strict SQL mode is disabled by default. When it is disabled, if we enter an invalid value that is not in the ENUM list, it returns an empty string. Let us understand this by using the example below. Example In the below example we have ...
Read More