Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to connect database in php

<?php
 $hostName = "localhost";
 $userName = "root";
 $password = "";
 $dbName = "database name";
 $conn= new mysqli($hostName,$userName,$password,$dbName);
 if($conn){
    echo "connected";
 }else{
    echo "not connected";
 }

  ?>
Comment

how to connect to a database in php

<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Comment

connect sql server php

//Connect MSSQL
$serverName = '192.xxx.xxx.xx';
$userName = 'usertest';
$userPassword = 'pwdtest';
$dbName = 'dbtest';
 
try{
	$conn = new PDO("sqlsrv:server=$serverName ; Database = $dbName", $userName, $userPassword);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(Exception $e){
	die(print_r($e->getMessage()));
}
 
//การ query และแสดงข้อมูล จัดเรียงตามฟิวด์ field1 แบบมากไปน้อย เริ่มที่เรคคอร์ดที่ 0-100
$query = " SELECT * FROM tbl 
ORDER BY field1 DESC
OFFSET 0 ROWS
FETCH NEXT 100 ROWS ONLY ";
$getRes = $conn->prepare($query);
$getRes->execute();
 
while($row = $getRes->fetch( PDO::FETCH_ASSOC ))
{
echo $row['field1']."<br />";
echo $row['field2']."<br />";
}
Comment

connect php in sql server

SQL SERVER 2012 conexion in PHP
<?php
    $serverName = "SERVER"; //serverNameinstanceName
    $connectionInfo = array( "Database"=>"base", "UID"=>"ex", "PWD"=>"******");
    $conn = sqlsrv_connect( $serverName, $connectionInfo);
;

        if( $conn ) {
             echo "Conexión establecida.<br />";
        }else{
            echo "Conexión no se pudo establecer.<br />";
            die( print_r( sqlsrv_errors(), true));
        }

    $sql = "SELECT name FROM [base].[dbo].[table]";
    $params = array();
    $options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
    $stmt = sqlsrv_query( $conn, $sql , $params, $options );

    $row_count = sqlsrv_num_rows( $stmt );
  

        if ($row_count === false)
           echo "Error al obtener datos.";
        else
           echo "bien";
        //echo $row_count;

        while( $row = sqlsrv_fetch_array( $stmt) ) {
              print json_encode($row);
        }

    sqlsrv_close($conn);
?>
Comment

PREVIOUS NEXT
Code Example
Php :: laravel migration rollback 
Php :: php artisan ui auth 
Php :: Carbon add 3 hours 
Php :: php carbon get timestamp 
Php :: laravel password verification 
Php :: the configuration file now needs a secret passphrase (blowfish_secret) 
Php :: laravel carbon count days between dates 
Php :: php array_merge 
Php :: flutter form set next input 
Php :: carbon parse subday 
Php :: switch between php version ubuntu nginx 
Php :: php is variable a number 
Php :: php get filename without extension 
Php :: php remove bom 
Php :: convert string to date php 
Php :: PHPspreadsheet getColumnDimension 
Php :: php maxupload 
Php :: phpspreadsheet setcellvalue row background color 
Php :: carbon time ago laravel 
Php :: sleep function in php 
Php :: how to hide .php extension using .htaccess 
Php :: blade switch 
Php :: wordpress escape for html 
Php :: file original extensions laravel 
Php :: Interval Between Different Dates 
Php :: wordpress if is in categroy 
Php :: php8.1 extensions 
Php :: how convert big text to array that text have br in laravel 
Php :: xampp check php version 
Php :: wordpress wpdb insert debug 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =