- 전체
- HTML
- Web Design (웹디자인)
- XE 응용 개발
- wordpress plugin dev
- Javascript & JavaScript Application
- MEAN Stack : full stack javascript
- angular js & ionic framework
- bootstrap
- WebGL, Three.js and Babylon.js
- restful api design
- mobile web
- node.js 응용
- Cloud Service 응용
- 웹 어셈블리 개발 [WASM, WebAssembly]
- 마이크로서비스, MSA (microservice architecture)
- WebGL / WebGPU
- next.js 개발
- micro frontend (마이크로프론트앤드)
- 전자상거래/쇼핑몰
- 서버 클라우드 (aws, azure, google)
[php worldpress] PHP query to SQL server database (wordpress)
[Question]
I am trying to communicate to a MSSQL Server database with PHP from a woocommerce website (to fetch data like products, categories etc.). But I get no results, here is my code:
$connectionInfo = array( "UID"=>$uid,
"PWD"=>$pwd,
"Database"=>$databaseName);
$conn = sqlsrv_connect( $serverName, $connectionInfo);
$tsql = "SELECT * FROM eshopItemsTable";
$stmt = sqlsrv_query($conn, $tsql);
//uncomment to get some results : $table = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC);
while( $table = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) {
print_r($table);
}
sqlsrv_free_stmt( $stmt);
sqlsrv_close( $conn);
with this code it prints nothing. But if I uncomment the line above while then I get some results but I dont get all of them (there are ~2000 items in the db but I get something like 10 items without the first one - which is obvious because I already consume the first row). What is the proper way to get all the results?
[Answer]
Seems something wrong with the while.
The while is ok, but seems like ends before that he had to.
I've looking for some solutions and this man had the same problem:
First of all gets the num of results:
$result_num = sqlsrv_num_rows( $result_count_res );
And then use a for instead of a while.
for($i = 0; $i < $result_num; $i++){
$data[] = sqlsrv_fetch_array( $result_res, SQLSRV_FETCH_ASSOC);
}
Consider also, a time out. Because you are attacking to another server...
[출처] https://stackoverflow.com/questions/67391986/php-query-to-sql-server-database-wordpress
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 4 |
AWS Certified Solutions Architect - Associate 2018 후기
| 졸리운_곰 | 2018.10.31 | 661 |
| 3 |
AWS 자격증 준비하기
| 졸리운_곰 | 2018.10.31 | 996 |
| 2 |
AWS 자격증 (아키텍트) 준비요령
| 졸리운_곰 | 2018.10.31 | 778 |
| 1 |
AWS Certified Solutions Architect – Associate Exam 시험 후기
| 졸리운_곰 | 2018.10.31 | 820 |

