SQL Server - How to set CharacterSet for connection?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ITSC
User
Posts: 4

SQL Server - How to set CharacterSet for connection?

Post by ITSC »

how i can use same this database connection

$serverName = "serverName";
$uid = "uid";
$pwd = "pwd";
$databaseName = "databaseName";
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$databaseName, "CharacterSet" => "UTF-8");

$homepageconn = sqlsrv_connect( $serverName, $connectionInfo);

in "Server Events and Client Scripts" -> "Database_Connecting"

I have PHPMaker v2018.0.1


kirondedshem
User
Posts: 642

Post by kirondedshem »

If you look into the help file server & client events you'll see an example on how to change the connection from the $info object in Database_Connecting(&$info), you can even var_dump the info object to see what other things to twaek like the port
NOTE 1:Enusre the database you are connecting to has the SAME EXACT structure as the one in development
NOTE 2: Ensure the connection info is all correct according to where db is setup and also update the port need be
BUt its something like this
function Database_Connecting(&$info) {
//var_dump($info);
// assume the scripts are generated with connection info for local PC
// connect to the production database
$info["host"] = "serverName";
$info["user"] = "uid";
$info["pass"] = "pwd";
$info["db"] = "databaseName";
}


Webmaster
User
Posts: 9425

Post by Webmaster »

With v2018.0.2, you can set additional connection info (for sqlsrv) in Database_Connecting server event, e.g.

$info["connectionInfo"] = ["CharacterSet" => "UTF-8"]; // Array of connection info

Note: From v2018.0.2, "CharacterSet" will be set to "UTF-8" automatically if project charset is "utf-8".


Post Reply