pdo 链接sqlserver
注意:需要根据PHP版本安装对应的依赖
<?php require_once __DIR__ . '/../config/_config.inc.php'; require_once __DIR__ . '/../api/src/autoload.php'; require_once __DIR__ . '/../api/v1/vendor/autoload.php'; use Shared\DB; $serverName = $host; $connectionInfo = array("Database" => $db_name, "UID" => $user, "PWD" => $pwd, "CharacterSet" => "UTF-8", "TrustServerCertificate" => "yes"); $conn = sqlsrv_connect($serverName, $connectionInfo); $DB = DB::connect([ 'host' => $PARAM_DB_host, 'dbname' => $cfg['db_name'], 'username' => $PARAM_DB_user, 'password' => $PARAM_DB_password, 'eamic_user' => 'Sync' ]); function getSpPrice(): array { global $conn, $log; $sql = " SELECT materialcode AS sp_code, bhsdj AS sp_unit_price, sl AS receipt_sp_tax_percentage, hsdj AS receipt_sp_unit_price_wtax FROM LC0019999.vw_movementpriceEAM "; $stmt = sqlsrv_query($conn, $sql); if ($stmt === false) { $log->write(sqlsrv_errors(), true); } $row_count = sqlsrv_num_rows($stmt); if ($row_count === false) { $log->write("Error al obtener datos"); } $data = []; while ($row = sqlsrv_fetch_array($stmt)) { $data[] = $row; } sqlsrv_close($conn); return $data; } function getSqlervSp(): array { global $log, $conn; $sql = "SELECT materialcode AS sp_code, materialname AS sp_name, specs AS sp_specification , unitname AS sp_unit FROM LC0019999.vw_materialEAM"; $stmt = sqlsrv_query($conn, $sql); if ($stmt === false) { $log->write(sqlsrv_errors(), true); } $row_count = sqlsrv_num_rows($stmt); if ($row_count === false) { $log->write("Error al obtener datos"); } $data = []; while ($row = sqlsrv_fetch_array($stmt)) { $data[] = $row; } sqlsrv_close($conn); return $data; }
标签:sp,sqlsrv,stmt,server,pdo,sql,data,conn,row From: https://www.cnblogs.com/xiaoyantongxue/p/17547267.html