thesaleboat Posted September 18, 2008 Share Posted September 18, 2008 Hello, I have created a MySQL Database which interacts with my PHP pages, and now I have to change the database to MS SQL. Does anyone have any good resources or tips/hints which could help me change over the database? Also I have a lot of php code, and queries. Could someone guide me on how to change this code, I have never used MS SQL before and I know it's expensive, so our company probably won't be buying it. Heres some snippets of my php code. <?php require_once('dbconnect.php'); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername = $_SESSION['myusername']; $rowalreadyexists = mysql_query("SELECT * FROM `users_subcategories` WHERE `users_subcategories`.`SubCategoryId` = '$subcategory' and `users_subcategories`.`username` = '$myusername'") or die(mysql_error()); $rowcount = mysql_num_rows($rowalreadyexists); if (!empty($_SESSION['myusername']) && $subcategory >= 1){ if ($rowcount == 0) { mysql_query("INSERT INTO `users_subcategories` (`username`, `SubCategoryId`) VALUES ('$myusername','$subcategory');") or die(mysql_error()); } } ?> And here is code for the progress chart: <?php require_once('dbconnect.php'); mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $myusername = $_SESSION['myusername']; $subcategoryID++; $rowalreadyexists = mysql_query("SELECT * FROM `users_subcategories` WHERE `users_subcategories`.`SubCategoryId` = '$subcategoryID' and `users_subcategories`.`username` = '$myusername'") or die(mysql_error()); $rowcount = mysql_num_rows($rowalreadyexists); if (!empty($_SESSION['myusername'])){ if ($rowcount == 1) { echo '<img src="images/Fullcompletion.gif" alt="100% completed" width="18" height="18" />'; } else echo '<img src="images/0completion.gif" alt="0% completed" width="18" height="18" />'; } else echo '<img src="images/0completion.gif" alt="0% completed" width="18" height="18" />'; ?> Link to comment https://forums.phpfreaks.com/topic/124823-solved-mysql-5-to-ms-sql-server-2003-help/ Share on other sites More sharing options...
MatthewJ Posted September 18, 2008 Share Posted September 18, 2008 $conn = mssql_connect($SERVER, $ADMIN_NAME, $ADMIN_PASS) or die ("Can't connect to Microsoft SQL Server"); mssql_select_db($DATABASE, $conn) or die ("Can't connect to Database"); $sql = "SELECT DispatchDateNTime, MoneyOrComp, RequestType, ReportNbr, BadgeNbr, ActualHours, PaidOvtHours, ActualOvtHours, Category, Criteria, UserID, RequestID, SecurityID, CAST (UserNarrative AS TEXT), CAST (DenyNarrative AS TEXT), EmpNbr, ActualHours, ActualOvtHours, PaidOvtHours, startTime, endTime, dateCreated, OutOfClass FROM Requests WHERE RequestID = '$reqID' AND SecurityID = '$guid'"; $result = mssql_query($sql, $conn) or die("Wrong database name"); $row_rsRes = mssql_fetch_assoc($result); $totalRows_rsRes = mssql_num_rows($result); That is a working piece of code from a script where I interact with mssql. Just make sure you have enabled all the mssql extensions in php, and change up your functions and everything should be okay. If you notice the CAST in the query, I found that I had to do that with fields in mssql that are of the type ntext. Hope that helps Link to comment https://forums.phpfreaks.com/topic/124823-solved-mysql-5-to-ms-sql-server-2003-help/#findComment-644877 Share on other sites More sharing options...
thesaleboat Posted September 18, 2008 Author Share Posted September 18, 2008 So i do not need the single quotes around names during the queries? This stinks i don't have MS SQL to test this out. Link to comment https://forums.phpfreaks.com/topic/124823-solved-mysql-5-to-ms-sql-server-2003-help/#findComment-644921 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.